﻿using BrightIdeasSoftware;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using BO;
using System.Collections;
using UI.Core;
using System.Data.SqlClient;
namespace UI
{
    public partial class ProductCustomerReport : ReportFormBase,IMenuForm
    {
        public ProductCustomerReport()
        {
            InitializeComponent();
        }

        protected override void InitGrid()
        {
            
            MyGrid.Columns.AddRange(new OLVColumn[] { 
             new OLVColumn(FieldHelper.cnName.Company, "CompanyName"),
              new OLVColumn(FieldHelper.cnName.Product, "ProductName"),
             new OLVColumn("家数", "Count"),
             
            });

           
        }
        IEnumerable mySource;

        protected override IEnumerable MySource
        {
            get
            {
                return mySource;
            }
        }
        protected override void FetchData()
        {
            var timeNow=DateTime.Now;
          
          var  sqlTxt = string.Format(
@"select Billing.CompanyName, Billing.ProductName, COUNT(distinct Billing.CustomerName) as Count
from Billing 
where Billing.CompanyName<>'' 
And Billing.TransDate>='{0}'
And Billing.TransDate<='{1}'
and Billing.HasDeleted=0
and Billing.IsConfirm=1
group by Billing.CompanyName,Billing.ProductName
order by Billing.CompanyName,Billing.ProductName
", BeginDate, EndDate);
            var dt = BinDataTableAdapter.GetDataTable( CommandType.Text,sqlTxt);
            mySource =dt.DefaultView;
        
        }
    }
}
